<?php
class gjz extends CI_Controller {
	function index() {
		$this->pub->logp('浏览关键字','1-2');
		$da = $this -> pub -> get_setting('关键字', 'Keyword');
		$this -> load -> view('adminx/gjz', $da);
	}

	function add() {
		$this->pub->logp('创建关键字','1-2');
		$da['gjz'] = $this -> input -> post('gjz');
		$da['content'] = $this -> input -> post('content');
		$da['state'] = $this -> input -> post('state');
		$da['is_wx'] = $this -> input -> post('is_wx');
		$this -> pub -> insert('gjz', $da);
		echo json_encode(array('type' => 1));
	}

	function up() {
		$this->pub->logp('关键字修改 - '. $this -> input -> post('idx'),'1-2');
		$da['gjz'] = $this -> input -> post('gjz');
		$da['content'] = $this -> input -> post('content');
		$da['state'] = $this -> input -> post('state');
		$da['is_wx'] = $this -> input -> post('is_wx');
		$this -> db -> update('gjz', $da, array('id' => $this -> input -> post('idx')));
		echo json_encode(array('type' => 1));
	}

	function get_one() {
		$this->pub->logp('获取关键字信息 - '. $this -> input -> post('idx'),'1-2');
		$q = $this -> db -> get_where('gjz', array('id' => $this -> input -> post('idx')));
		if ($q -> num_rows() > 0) {
			$da = $q -> row_array(0);
			$da['typex'] = 1;
			echo json_encode($da);
		} else {
			echo json_encode(array('typex' => 2));
		}
	}

	function del() {
		$this->pub->logp('关键字删除 - '. $this -> input -> post('idx'),'1-2');
		$da['type'] = 1;
		$this -> db -> update('gjz', array('gjz_del' => 2), array('id' => $this -> input -> post('idx')));
		echo json_encode($da);
	}

	function get() {
		$this->pub->logp('获取关键字信息','1-2');
		if ($this -> input -> post('key')) {
			$this -> db -> like('gjz', $this -> input -> post('key'));
		}
		$this -> db -> where('gjz_del', 1);
		$q = $this -> db -> get_where('gjz');
		$state[1] = '启用';
		$state[2] = '关闭';
		$da['content'] = '';

		foreach ($q->result_array() as $v) {
			$da['content'] .= '<tr>';
			$da['content'] .= '<td>' . $v['gjz'] . '</td>';
			$da['content'] .= '<td>' . $v['content'] . '</td>';
			$da['content'] .= '<td>' . $state[$v['state']] . '</td>';
			$da['content'] .= '<td><button onclick="show_up(\'' . $v['id'] . '\')" type="button"  class="btn default"><i class="fa fa-edit"></i>修改</button>  <button onclick="del(\'' . $v['id'] . '\',\'' . $v['gjz'] . '\')" type="button" class="btn red"><i class="fa fa-trash-o"></i> 删除</button></td>';
			$da['content'] .= '</tr>';
		}
		$da['type'] = 1;
		echo json_encode($da);
	}

}
?>